﻿(function () {
    schoolsGrid = function(param){
		this.isMainHeader = false;
		numberOfRows = 0;	
	}
	
	schoolsGrid.prototype = {
		
		init: function(){		
			var body = document.body;				
			var element = document.createElement("table");
			body.appendChild(element);	
			mainTable = document.body.getElementsByTagName("table")[0];	
			mainTable.border = "1px";

		},
		
		addHeader:  function(par) {		

			if (!this.isMainHeader) {	
				var rowElement = document.createElement("tr");		
				mainTable.appendChild(rowElement);		
				var headerEl = document.body.getElementsByTagName("tr")[numberOfRows];				
				for (var i = 0;i<=3;i++) {
					var dataElement = document.createElement("th");
					dataElement.innerHTML += par[i];
					headerEl.appendChild(dataElement);					
				}
			
				this.isMainHeader = true;
				numberOfRows ++;
			}	
		},
	
		addRow:  function(par) {	
			
			var rowElement = document.createElement("tr");	
			mainTable.appendChild(rowElement);		
			var row = document.body.getElementsByTagName("tr")[numberOfRows];	
		

			row.setAttribute("id", par[0]);			
			for (var i = 0;i<=3;i++) {
				var dataElement = document.createElement("td");
				dataElement.innerHTML += par[i];
				row.appendChild(dataElement);
			}
			
			numberOfRows++;
		},
				
		render:  function() {		
		
		mainTable.style.visibility = "visible";		
		
		}
	}
	
	var grid = new schoolsGrid();
	grid.init();
	//Adding elements and second header attempt
	grid.addHeader(["Name","Location","Total Students","Specialty"]);
	grid.addHeader(["Name","Location","Total Students","Specialty"]);
	grid.addRow(["PMG","Burgas",400,"Mathematics"]);
	grid.addRow(["TUES","Sofia",500,"IT"]);
	grid.addRow(["Telerik Academy","Sofia",5000,"IT"]);
	grid.render();
	
})();